package com.app.dao;

import org.hibernate.Query;

import com.app.dao.entity.Book;

public class BookDAO extends BaseDAO<Long, Book> {

	@Override
	public Book findByID(Long id) {
		return (Book) getSession().get(Book.class, id);

	}

	//
	public Book createBook(String bookTitle, String bookUrl) {
		Book book = new Book(bookTitle, bookUrl);
		saveOrUpdate(book);
		return book;
	}

	public Book findBook(String bookTitle) throws Exception {

		Query q = getSession().createQuery(
				"from Book where bookTitle = :bookTitle");
		q.setString("bookTitle", bookTitle);
		Book book = (Book) q.uniqueResult();
		return (book);
	}

	public void deleteBook(Book book) throws Exception {
		getSession().delete(book);

	}

}
